<?php

if (!isset($_SESSION))
    session_start();
/* import */
include_once('../Presenter/LoginPresenter.php');
if (!isset($_SESSION))
    session_start();
if (!array_key_exists('logado', $_SESSION))
    $_SESSION['logado'] = 'deslogado';

if ($_SESSION['logado'] == 'logado') {
    $loginPresenter = new LoginPresenter();
    $loginPresenter->__redi();
    $loginPresenter->__logout();
} else {
    extract($_POST);
    $Usuario = addslashes($Usuario);
    $Senha = addslashes($Senha);
    if ($Usuario != "" && $Senha != "") {
        $loginPresenter = new LoginPresenter();
        $retorno = $loginPresenter->__login($Usuario, $Senha);
        if ($retorno) {
            $loginPresenter->__redi();
            $loginPresenter->__logout();
        } else {
            header("Location: http://localhost/Portal_DSW/index.php?errorLogin=1");
            

        }
    } else {
        header("Location: http://localhost/Portal_DSW/index.php?errorLogin=2");
        

    }
}
?>